<!DOCTYPE>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>cartoCss_edit</title>
    <style type="text/css">
        body {
            margin: 0;
            overflow: hidden;
            background: #fff;
        }

        #map {
            position: relative;
            height: 553px;
            border: 1px solid #3473b7;
        }
        #text{
            background-color: #bbbbbb;
            font-size: 20px;
            padding-top: 5px;
            padding-bottom: 5px;
        }
        #cartoContainer{
            position: absolute;
            top: 10px;
            right: 10px;
        }
        #cartoContainer.hide{
            display: none;
        }
        #cartocssStr{
            height: 450px;
            width: 350px;
            display: block;
        }
    </style>
    <link href='./css/bootstrap.min.css' rel='stylesheet' />
    <link href='./css/bootstrap-responsive.min.css' rel='stylesheet' />
    <script src='../libs/SuperMap.Include.js'></script>
    <!--使用矢量地图编辑器必须引用语言包-->
    <!--<script src='../libs/Lang/zh-CN.js'></script>-->
    <!--英文语言包-->
    <!--<script src='../libs/Lang/en.js'></script>-->
    <script type="text/javascript">
        var map, layer, lat, lon, editor,geolocate, infowin,lonLat,geometryInfo,cartoCssStr,cartoContainer, host = document.location.toString().match(/file:\/\//) ? "http://localhost:8090" : 'http://' + document.location.host;
        url = host + "/iserver/services/map-china400/rest/maps/China";

        function init() {
            if(!document.createElement('canvas').getContext) {
                alert('您的浏览器不支持 canvas，请升级');
                return;
            }
            //语言默认为跟当前浏览器的语言一样,当要切换至英文时,要先引入英文的语言包，然后用以下语言切换
            //SuperMap.Lang.setCode("en");

            map = new SuperMap.Map("map", {controls: [
                new SuperMap.Control.ScaleLine(),
                new SuperMap.Control.Zoom(),
                new SuperMap.Control.Navigation({
                    dragPanOptions: {
                        enableKinetic: true
                    }
                })]
            });
            cartoCssStr=document.getElementById("cartocssStr");
            cartoCssStr.setAttribute("disabled",true);
            var cartoCss=cartoCssStr.value;
            layer = new SuperMap.Layer.TiledVectorLayer("China", url,{cacheEnabled:true,returnAttributes:true},{useLocalStorage:true,cartoCss:cartoCss});
            editor=new SuperMap.Control.TiledVectorLayerEditor({"layer":layer,"position":{"x":0,"y":0}});
            editor.events.on({"cartocsschange":function(event){
                cartoCssStr.value=event.cartoCss;
            }});
            editor.activate();
            layer.events.on({"layerInitialized": addLayer});

            cartoContainer=document.getElementById("cartoContainer");
        }


        function addLayer() {
            map.addLayers([layer]);
            map.addControls([editor]);
            var center = new SuperMap.LonLat(11793760,4407704);
            map.setCenter(center, 2);
        }

        function refresh(){
            editor.position={"x":150,"y":536};
            editor.autoHide=true;
            editor.editorName="我的矢量地图编辑器";
            editor.refresh();
        }
        function toggle(event){
            event=event||window.event;
            var element=SuperMap.Event.element(event);
            SuperMap.Element.toggleClass(cartoContainer,"hide");
            if(SuperMap.Element.hasClass(cartoContainer,"hide")){
                element.innerHTML="打开";
            }else{
                element.innerHTML="隐藏";
            }
        }

    </script>
</head>
<body onload="init()">
<div id="map"></div>
<a href="#" style="position: absolute;right: 15px;top: 15px;z-index: 100" onclick="toggle(event)">隐藏</a>
<div id="cartoContainer">
    <div id="text">CartoCSS样式表：</div>
    <textarea id="cartocssStr" style="height: 270px;width: 230px">
    </textarea>
</div>
<button onclick="refresh()">refresh</button>
</body>
</html>
